<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>React之组件的生命周期以及属性状态（三） | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="JavaScript,react,">
  

  <meta name="description" content="一、什么是生命周期  组件本质是状态机，输入确定，输出一定确定 一个state对应一个render，状态转换的时候会触发不同的函数，从而让开发者有机会做出响应，可以用事件的思路理解状态，但是事件与事件之间没有关联，而状态与状态之间可能会有关联   二、初始化阶段设置初始的属性与状态  getDefaultProps：设置初始的属性，只在第一次调用，实例之间共享引用 getInitialState：">
<meta name="keywords" content="JavaScript,react">
<meta property="og:type" content="article">
<meta property="og:title" content="React之组件的生命周期以及属性状态（三）">
<meta property="og:url" content="http://blog.poetries.top/2017/11/19/react-study-life-props-state/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="一、什么是生命周期  组件本质是状态机，输入确定，输出一定确定 一个state对应一个render，状态转换的时候会触发不同的函数，从而让开发者有机会做出响应，可以用事件的思路理解状态，但是事件与事件之间没有关联，而状态与状态之间可能会有关联   二、初始化阶段设置初始的属性与状态  getDefaultProps：设置初始的属性，只在第一次调用，实例之间共享引用 getInitialState：">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/464.png">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/465.png">
<meta property="og:updated_time" content="2020-08-15T04:25:31.930Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="React之组件的生命周期以及属性状态（三）">
<meta name="twitter:description" content="一、什么是生命周期  组件本质是状态机，输入确定，输出一定确定 一个state对应一个render，状态转换的时候会触发不同的函数，从而让开发者有机会做出响应，可以用事件的思路理解状态，但是事件与事件之间没有关联，而状态与状态之间可能会有关联   二、初始化阶段设置初始的属性与状态  getDefaultProps：设置初始的属性，只在第一次调用，实例之间共享引用 getInitialState：">
<meta name="twitter:image" content="https://poetries1.gitee.io/img-repo/2019/10/464.png">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、什么是生命周期"><span class="toc-text">一、什么是生命周期</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、初始化阶段"><span class="toc-text">二、初始化阶段</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、运行中阶段"><span class="toc-text">三、运行中阶段    </span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、销毁阶段"><span class="toc-text">四、销毁阶段</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#五、属性状态"><span class="toc-text">五、属性状态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#状态的用法"><span class="toc-text">状态的用法</span></a></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-react-study-life-props-state" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">React之组件的生命周期以及属性状态（三）</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2017.11.19</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 2.1k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 9分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <h2 id="一、什么是生命周期"><a href="#一、什么是生命周期" class="headerlink" title="一、什么是生命周期"></a>一、什么是生命周期</h2><p><img src="https://poetries1.gitee.io/img-repo/2019/10/464.png" alt></p>
<ul>
<li>组件本质是状态机，输入确定，输出一定确定</li>
<li>一个<code>state</code>对应一个<code>render</code>，状态转换的时候会触发不同的函数，从而让开发者有机会做出响应，可以用事件的思路理解状态，但是事件与事件之间没有关联，而状态与状态之间可能会有关联</li>
</ul>
<p><img src="https://poetries1.gitee.io/img-repo/2019/10/465.png" alt></p>
<h2 id="二、初始化阶段"><a href="#二、初始化阶段" class="headerlink" title="二、初始化阶段"></a>二、初始化阶段</h2><p><strong>设置初始的属性与状态</strong></p>
<ul>
<li><code>getDefaultProps</code>：设置初始的属性，只在第一次调用，实例之间共享引用</li>
<li><code>getInitialState</code>：设置初始的状态</li>
<li><code>componentWillMount</code>：组件将要加载，<code>render</code>之前最后一次修改状态的机会</li>
<li><code>render</code>：只能访问<code>this.props</code>与<code>this.state</code>，只有一个顶层标签（组件），不允许修改状态和<code>DOM</code>输出</li>
<li><code>componentDidMount</code>：成功<code>render</code>并渲染完成真实<code>DOM</code>之后出发，可以修改<code>DOM</code>，要操作<code>DOM</code>也必须在这个阶段完成</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    <span class="comment">// 第一步执行顺序：设置初始的属性，指执行一次</span></span><br><span class="line">    getDefaultProps:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            name:<span class="string">'一个盒子'</span>,</span><br><span class="line">            title:<span class="string">'box'</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 第二步执行顺序：设置初始的状态</span></span><br><span class="line">    getInitialState:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            sss: <span class="keyword">this</span>.props.name</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 第三步执行：组件将要加载的时候，最后一次可以修改状态的机会</span></span><br><span class="line">    componentWillMount:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.setState(&#123;</span><br><span class="line">            sss:<span class="string">'修改状态'</span></span><br><span class="line">        &#125;)</span><br><span class="line">        <span class="comment">// alert('componentWillMount')</span></span><br><span class="line">        <span class="comment">// 这里是没有办法获取到这个节点的</span></span><br><span class="line">        <span class="comment">// var box = this.refs.box;</span></span><br><span class="line">        <span class="comment">// alert(box.clientWidth)</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 第四步：render渲染</span></span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="comment">// console.log(this)</span></span><br><span class="line">        <span class="keyword">var</span> styles = &#123;</span><br><span class="line">            position:<span class="string">'absolute'</span>,</span><br><span class="line">            width: <span class="string">'100px'</span>,</span><br><span class="line">            height: <span class="string">'100px'</span>,</span><br><span class="line">            color: <span class="string">'red'</span>,</span><br><span class="line">            background: <span class="string">'lime'</span></span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">ref</span>=<span class="string">"box"</span> <span class="attr">style</span>=<span class="string">&#123;styles&#125;</span>&gt;</span>&#123;this.props.title&#125;&#123;this.state.sss&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 第五步：组件加载完成，只有在这一个阶段，我们才可以操作DOM节点</span></span><br><span class="line">    componentDidMount:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="comment">// alert('componentDidMount')</span></span><br><span class="line">        <span class="comment">// 下面的this指向组件</span></span><br><span class="line">        <span class="built_in">console</span>.log(<span class="keyword">this</span>)</span><br><span class="line">        <span class="keyword">var</span> box = <span class="keyword">this</span>.refs.box;</span><br><span class="line">        <span class="keyword">var</span> timer = <span class="literal">null</span>;</span><br><span class="line">        <span class="keyword">var</span> n = <span class="number">0</span>;</span><br><span class="line">        box.onclick = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.log(<span class="number">1</span>)</span><br><span class="line">            <span class="comment">// 这个this指向box</span></span><br><span class="line">            <span class="built_in">console</span>.log(<span class="keyword">this</span>)</span><br><span class="line">            <span class="keyword">var</span> This = <span class="keyword">this</span>;</span><br><span class="line">            timer = setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">                <span class="comment">// 这个this指向window</span></span><br><span class="line">                <span class="comment">// console.log(this)</span></span><br><span class="line">                n++;</span><br><span class="line">                This.style.left = n + <span class="string">'px'</span>;</span><br><span class="line">                This.style.top = n + <span class="string">'px'</span>;</span><br><span class="line">            &#125;,<span class="number">60</span>)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Demo</span>/&gt;</span></span>,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br></pre></td></tr></table></figure>
<h2 id="三、运行中阶段"><a href="#三、运行中阶段" class="headerlink" title="三、运行中阶段    "></a>三、运行中阶段    </h2><ul>
<li><code>componentWillReceiveProps</code>：父组件修改属性触发，可以修改新属性，修改状态</li>
<li><code>shouldCompoenntUpdate</code>：组件是否更新，返回<code>false</code>会阻止<code>render</code>调用，<code>render</code>后面的函数都不会执行</li>
<li><code>componentWillUpdate</code>：不能修改属性与状态，用于日志打印与数据获取</li>
<li><code>reder</code>：只能访问<code>this.props与this.state</code>，只有一个顶层标签（组件），不允许修改状态和<code>DOM</code>输出</li>
<li><code>componentDidUpdate</code>：可以修改<code>DOM</code></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> HelloReact = React.createClass(&#123;</span><br><span class="line">    <span class="comment">// 组件将要接收新的属性</span></span><br><span class="line">    componentWillReceiveProps:<span class="function"><span class="keyword">function</span>(<span class="params">newProps</span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'componnetWillReceiveProps'</span>,<span class="number">1</span>)</span><br><span class="line">        <span class="built_in">console</span>.log(newProps)</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 是否允许组件更新，返回true或者false，一般不会改变它的默认值：true</span></span><br><span class="line">    shouldComponentUpdate:<span class="function"><span class="keyword">function</span>(<span class="params">newProps,newState</span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'shouldComponentUpdate'</span>,<span class="number">2</span>)</span><br><span class="line">        <span class="built_in">console</span>.log(newProps,newState)</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 组件将要更新</span></span><br><span class="line">    componentWillUpdate:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'componentWillUpdate'</span>,<span class="number">3</span>)</span><br><span class="line">    &#125;,</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'render'</span>,<span class="number">4</span>)</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">p</span>&gt;</span>Hello &#123;this.props.name?this.props.name:'React'&#125;<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 组件更新完毕</span></span><br><span class="line">    componentDidUpdate:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'componentDidUpdate'</span>,<span class="number">5</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    getInitialState:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            name:<span class="string">''</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    handleChange:<span class="function"><span class="keyword">function</span>(<span class="params">e</span>)</span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.setState(&#123;</span><br><span class="line">            name:e.target.value</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123; </span><br><span class="line">        <span class="keyword">return</span>(</span><br><span class="line">            &lt;div&gt;</span><br><span class="line">                &lt;HelloReact name=&#123;<span class="keyword">this</span>.state.name&#125;/&gt;</span><br><span class="line">                &lt;input type=<span class="string">"text"</span> onChange=&#123;<span class="keyword">this</span>.handleChange&#125; /&gt;</span><br><span class="line">            &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">        )</span></span><br><span class="line"><span class="regexp">    &#125;</span></span><br><span class="line"><span class="regexp">&#125;)</span></span><br><span class="line"><span class="regexp">ReactDOM.render(&lt;Demo/</span>&gt;,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br></pre></td></tr></table></figure>
<h2 id="四、销毁阶段"><a href="#四、销毁阶段" class="headerlink" title="四、销毁阶段"></a>四、销毁阶段</h2><ul>
<li><code>componentWillUnmount</code>：组件将要卸载</li>
<li>在<code>ReactDOM</code>中提供一个方法<code>unmountComponentAtNode</code>(删除节点的名字)</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> HelloReact = React.createClass(&#123;</span><br><span class="line">    <span class="comment">// 组件将要接收新的属性</span></span><br><span class="line">    componentWillReceiveProps:<span class="function"><span class="keyword">function</span>(<span class="params">newProps</span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'componnetWillReceiveProps'</span>,<span class="number">1</span>)</span><br><span class="line">        <span class="built_in">console</span>.log(newProps)</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 是否允许组件更新，返回true或者false，一般不会改变它的默认值：true</span></span><br><span class="line">    shouldComponentUpdate:<span class="function"><span class="keyword">function</span>(<span class="params">newProps,newState</span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'shouldComponentUpdate'</span>,<span class="number">2</span>)</span><br><span class="line">        <span class="built_in">console</span>.log(newProps,newState)</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 组件将要更新</span></span><br><span class="line">    componentWillUpdate:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'componentWillUpdate'</span>,<span class="number">3</span>)</span><br><span class="line">    &#125;,</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'render'</span>,<span class="number">4</span>)</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">p</span>&gt;</span>Hello &#123;this.props.name?this.props.name:'React'&#125;<span class="tag">&lt;/<span class="name">p</span>&gt;</span></span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 组件更新完毕</span></span><br><span class="line">    componentDidUpdate:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'componentDidUpdate'</span>,<span class="number">5</span>)</span><br><span class="line">    &#125;,</span><br><span class="line">    componentWillUnmount:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">'BOOOOOOOOOOOOOOOOOM'</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    getInitialState:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            name:<span class="string">''</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    handleChange:<span class="function"><span class="keyword">function</span>(<span class="params">e</span>)</span>&#123;</span><br><span class="line">        <span class="comment">// 利用input输入的内容来卸载组件</span></span><br><span class="line">        <span class="keyword">if</span>(e.target.value == <span class="string">'1234'</span>)&#123;</span><br><span class="line">            ReactDOM.unmountComponentAtNode(<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br><span class="line">            <span class="comment">// 写上这个return是为了不执行下面的语句，减少代码执行时间</span></span><br><span class="line">            <span class="keyword">return</span> ;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">this</span>.setState(&#123;</span><br><span class="line">            name:e.target.value</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="comment">// 通过判断state的状态来卸载组件</span></span><br><span class="line">       <span class="comment">/* if( this.state.name == '1234')&#123;</span></span><br><span class="line"><span class="comment">            return &lt;div&gt;1234&lt;/div&gt;</span></span><br><span class="line"><span class="comment">        &#125;*/</span></span><br><span class="line">        <span class="keyword">return</span>(</span><br><span class="line">            &lt;div&gt;</span><br><span class="line">                &lt;HelloReact name=&#123;<span class="keyword">this</span>.state.name&#125;/&gt;</span><br><span class="line">                &lt;input type=<span class="string">"text"</span> onChange=&#123;<span class="keyword">this</span>.handleChange&#125; /&gt;</span><br><span class="line">            &lt;<span class="regexp">/div&gt;</span></span><br><span class="line"><span class="regexp">        )</span></span><br><span class="line"><span class="regexp">    &#125;</span></span><br><span class="line"><span class="regexp">&#125;)</span></span><br><span class="line"><span class="regexp">ReactDOM.render(&lt;Demo/</span>&gt;,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br></pre></td></tr></table></figure>
<h2 id="五、属性状态"><a href="#五、属性状态" class="headerlink" title="五、属性状态"></a>五、属性状态</h2><p><strong>属性的含义与用法</strong></p>
<ul>
<li>含义：<code>props = properties</code></li>
<li>属性：一个事物的性质与关系，属性往往是与生俱来，无法自己改变的</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 组件传递props</span></span><br><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">div</span>&gt;</span>&#123;this.props.title&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Demo</span> <span class="attr">title</span>=<span class="string">&#123;</span>"<span class="attr">Demo</span>"&#125;/&gt;</span></span>,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br><span class="line"><span class="string">``</span><span class="string">` </span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">`</span><span class="string">``</span>javascript</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">    ...this.props</span></span><br><span class="line"><span class="comment">    props的一个语法糖，可以将父组件中的全部属性复制给子组件，</span></span><br><span class="line"><span class="comment">    如果是这个标签本身拥有的这个属性</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> (<span class="xml"><span class="tag">&lt;<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">            <span class="tag">&lt;<span class="name">div</span>&gt;</span>&#123;this.props.title&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="xml">            <span class="tag">&lt;<span class="name">a</span> &#123;<span class="attr">...this.props</span>&#125;&gt;</span>&#123;this.props.title&#125;<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">var</span> props = &#123;</span><br><span class="line">    title:<span class="string">'百度'</span>,</span><br><span class="line">    href:<span class="string">'http://www.baidu.com'</span></span><br><span class="line">&#125;</span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Demo</span> &#123;<span class="attr">...props</span>&#125;/&gt;</span></span>,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br></pre></td></tr></table></figure>
<ul>
<li><code>this.props.chilidren</code></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">    this.props.children</span></span><br><span class="line"><span class="comment">    children没有与组件的属性一一对应，表示组件的所有子节点</span></span><br><span class="line"><span class="comment">    一般用于列表</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="built_in">console</span>.log(React)</span><br><span class="line"><span class="keyword">var</span> List = React.createClass(&#123;</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span>(<span class="xml"><span class="tag">&lt;<span class="name">ul</span>&gt;</span></span></span><br><span class="line"><span class="xml">            &#123;</span></span><br><span class="line"><span class="xml">                /*</span></span><br><span class="line"><span class="xml">                    列表项的数量以及内容不确定，在创建模板的时候需确定</span></span><br><span class="line"><span class="xml">                    利用this.props.chilidren从父组件获取需要的内容</span></span><br><span class="line"><span class="xml">                    利用React.Children.map方法进行children的遍历</span></span><br><span class="line"><span class="xml">                */</span></span><br><span class="line"><span class="xml">                React.Children.map(this.props.children,function(child)&#123;</span></span><br><span class="line"><span class="xml">                    return <span class="tag">&lt;<span class="name">li</span>&gt;</span>&#123;child&#125;<span class="tag">&lt;/<span class="name">li</span>&gt;</span></span></span><br><span class="line"><span class="xml">                &#125;)</span></span><br><span class="line"><span class="xml">            &#125;</span></span><br><span class="line"><span class="xml">        <span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">ReactDOM.render(</span><br><span class="line">    &lt;List&gt;</span><br><span class="line">        &lt;h1&gt;<span class="xml"><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">""</span>&gt;</span>百度<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span>&lt;<span class="regexp">/h1&gt;</span></span><br><span class="line"><span class="regexp">        &lt;a href="http:/</span><span class="regexp">/www.baidu.com"&gt;http:/</span><span class="regexp">/www.baidu.com&lt;/</span>a&gt;</span><br><span class="line">    &lt;<span class="regexp">/List&gt;,</span></span><br><span class="line"><span class="regexp">    document.getElementById("app")</span></span><br><span class="line"><span class="regexp">)</span></span><br></pre></td></tr></table></figure>
<ul>
<li><code>PropTypes</code></li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 属性验证：PropTypes   </span></span><br><span class="line"><span class="comment">// 验证组件的属性是否符合要求</span></span><br><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    PropTypes:&#123;</span><br><span class="line">        <span class="comment">// 要求title的类型必须是一个字符串</span></span><br><span class="line">        title:React.PropTypes.string.isRequired</span><br><span class="line">    &#125;,</span><br><span class="line">    render:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="xml"><span class="tag">&lt;<span class="name">div</span>&gt;</span>&#123;this.props.title&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Demo</span> <span class="attr">title</span>=<span class="string">&#123;</span>'<span class="attr">title</span>'&#125; /&gt;</span></span>,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br></pre></td></tr></table></figure>
<p><strong>属性的两种用法</strong></p>
<ul>
<li><code>&lt;Demo   title=?  /&gt;</code> <strong><code>？</code>中的内容可以是</strong><ul>
<li>字符串</li>
<li>对象<code>{}</code></li>
<li>数组<code>{[1,2,3]}</code></li>
<li>变量<code>{var}</code></li>
</ul>
</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&lt;Demo  &#123;…props&#125; /&gt;</span><br><span class="line"><span class="keyword">var</span>  props = &#123;</span><br><span class="line">	one:”<span class="number">123</span>”,</span><br><span class="line">	two:”<span class="number">456</span>”</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>状态的含义与用法</strong></p>
<ul>
<li><code>state</code></li>
<li>状态：事物所处的状况</li>
<li>状态是由事物自行处理，不断变化的。父组件与子组件都无法改变他的状态</li>
</ul>
<h2 id="状态的用法"><a href="#状态的用法" class="headerlink" title="状态的用法"></a>状态的用法</h2><ul>
<li><code>getInitialState</code>：初始化状态</li>
<li><code>setState</code>：更新状态</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">    state 状态的意思，一般在页面中存在状态的变化以及涉及到与状态相关的</span></span><br><span class="line"><span class="comment">        东西的时候会用他</span></span><br><span class="line"><span class="comment">    作用：根据不同的状态显示不同的UI界面</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    <span class="comment">// 设置初始的状态</span></span><br><span class="line">    getInitialState: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            <span class="comment">// 这里的值可以是一个boolean，string，function</span></span><br><span class="line">            onOff: <span class="literal">true</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    handleClick:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="comment">// 通过点击事件来修改状态值，原来的状态值需要使用this.state获取</span></span><br><span class="line">        <span class="keyword">this</span>.setState(&#123;</span><br><span class="line">            onOff: !<span class="keyword">this</span>.state.onOff</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;,</span><br><span class="line">    render: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="comment">// 每一个更新状态的时候，这个render函数都会重新被调用</span></span><br><span class="line">        <span class="keyword">return</span> (<span class="xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">onClick</span>=<span class="string">&#123;this.handleClick&#125;</span>&gt;</span>&#123;this.state.onOff?'data1':'data2'&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Demo</span> /&gt;</span></span>,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">var</span> Demo = React.createClass(&#123;</span><br><span class="line">    <span class="comment">// 设置默认的属性</span></span><br><span class="line">    getDefaultProps: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            name: <span class="string">'现在的时间是：'</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="comment">// 设置初始的状态</span></span><br><span class="line">    getInitialState: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="keyword">return</span> &#123;</span><br><span class="line">            time: <span class="keyword">new</span> <span class="built_in">Date</span>().toLocaleTimeString()</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;,</span><br><span class="line">    changTime:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="comment">// 在定时器中使用this.setState的时候需要将这个this变保存起来</span></span><br><span class="line">        <span class="keyword">var</span> that = <span class="keyword">this</span>;</span><br><span class="line">        setInterval(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">            that.setState(&#123;</span><br><span class="line">                time:<span class="keyword">new</span> <span class="built_in">Date</span>().toLocaleTimeString()</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;,<span class="number">1000</span>)</span><br><span class="line">    &#125;,</span><br><span class="line">    render: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">        <span class="comment">// 每一个更新状态的时候，这个render函数都会重新被调用</span></span><br><span class="line">        <span class="keyword">return</span> (<span class="xml"><span class="tag">&lt;<span class="name">div</span> <span class="attr">onClick</span>=<span class="string">&#123;this.changTime()&#125;</span>&gt;</span>&#123;this.props.name&#125;&#123;this.state.time&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">ReactDOM.render(<span class="xml"><span class="tag">&lt;<span class="name">Demo</span> <span class="attr">name</span>=<span class="string">'北京时间'</span>/&gt;</span></span>,<span class="built_in">document</span>.getElementById(<span class="string">"app"</span>))</span><br></pre></td></tr></table></figure>
<p><strong>属性与状态的对比</strong></p>
<ul>
<li>都是纯<code>JS</code>对象，使用<code>｛｝</code>创建的对象</li>
<li>都会触发<code>render</code>更新</li>
<li>都具有确定性，给定相同的属性或者是相同的状态，结果是相同的</li>
</ul>
<p><strong>属性与状态的区分</strong></p>
<ul>
<li>组件在运行时需要修改的数据就是状态</li>
<li>所有的数据都可以变成状态</li>
</ul>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2017/11/19/react-study-jsx-dom/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2017/11/19/react-study-event/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
